package leetcode每日一题;

import java.util.stream.Stream;

/**
 * 1. 问题描述
 *
 * 2. 算法分析
 *
 * 3. 代码实现
 *
 */
@SuppressWarnings("all")
public class 拼接最大数_困难 {
    public static void main(String[] args) {
        int[] num1 = {3, 4, 6, 5};
        int[] num2 = {9, 1, 2, 5, 8, 3};
        System.out.println(choose(num1,num2,0,5,4));
    }
    public static int[] maxNumber(int[] nums1, int[] nums2, int k) {
        return null;
    }

    /**
     * 从数组1的起始索引为s1的数组开始
     * 从数组2的起始索引为s2的数组开始
     * 找到合适的值
     * @param nums1
     * @param nums2
     * @param s1
     * @param s2
     * @param k
     * @return
     */
    public static int choose(int[] nums1,int[] nums2,int s1,int s2,int k) {
        int max1 = nums1[s1];
        int max2 = nums2[s2];
        int choose = max1;
        int cur1 = s1;
        int cur2 = s2;
        int len1 = nums1.length - s1;
        int len2 = nums2.length - s2;
        for (int i = s1; i < nums1.length; i++) {
            if (nums1[i] >= max1) {
                max1 = nums1[i];
                cur1 = i;
            }
        }
        for (int i = s2; i < nums2.length; i++) {
            if (nums2[i] >= max2) {
                max2 = nums2[i];
                cur2 = i;
            }
        }
        if (len1-cur1-1+len2 >= k) {
            if (max1 > max2) {
                choose = max1;
            } else {
                choose = max2;
            }
        } else if (len2-cur2-1+len1 >= k) {
            if (max2 > max1) {
                choose = max2;
            } else {
                choose = max1;
            }
        }
        return choose;
    }
}
